﻿using System;
using System.Configuration;
using System.Web.Security;

namespace VioletDevelopmentLaboratory.Net.Web.Configuration
{
	public sealed class HealthMonitoringProviderSettings
	{
		public HealthMonitoringProviderSettings()
		{
		}

		private string name;

		public string Name
		{
			get { return name; }
			set { name = value; }
		}

		private string type;

		public string Type
		{
			get { return type; }
			set { type = value; }
		}

		private string connectionStringName;

		public string ConnectionStringName
		{
			get { return connectionStringName; }
			set { connectionStringName = value; }
		}

		private string bcc;

		public string Bcc
		{
			get { return bcc; }
			set { bcc = value; }
		}

		private string bodyFooter;

		public string BodyFooter
		{
			get { return bodyFooter; }
			set { bodyFooter = value; }
		}

		private string bodyHeader;

		public string BodyHeader
		{
			get { return bodyHeader; }
			set { bodyHeader = value; }
		}

		private bool buffer;

		public bool Buffer
		{
			get { return buffer; }
			set { buffer = value; }
		}

		private string bufferMode;

		public string BufferMode
		{
			get { return bufferMode; }
			set { bufferMode = value; }
		}

		private string cc;

		public string Cc
		{
			get { return cc; }
			set { cc = value; }
		}

		private int commandTimeout;

		public int CommandTimeout
		{
			get { return commandTimeout; }
			set { commandTimeout = value; }
		}

		private bool detailedTemplateErrors;

		public bool DetailedTemplateErrors
		{
			get { return detailedTemplateErrors; }
			set { detailedTemplateErrors = value; }
		}

		private string from;

		public string From
		{
			get { return from; }
			set { from = value; }
		}

		private int maxEventDetailLength;

		public int MaxEventDetailLength
		{
			get { return maxEventDetailLength; }
			set { maxEventDetailLength = value; }
		}

		private int maxEventLengthForSimpleMessage;

		public int MaxEventLengthForSimpleMessage
		{
			get { return maxEventLengthForSimpleMessage; }
			set { maxEventLengthForSimpleMessage = value; }
		}

		private int maxSizeForSimpleMessage;

		public int MaxSizeForSimpleMessage
		{
			get { return maxSizeForSimpleMessage; }
			set { maxSizeForSimpleMessage = value; }
		}

		private int maxEventCountForTemplateMessage;

		public int MaxEventCountForTemplateMessage
		{
			get { return maxEventCountForTemplateMessage; }
			set { maxEventCountForTemplateMessage = value; }
		}

		private int maxMessagesPerNotification;

		public int MaxMessagesPerNotification
		{
			get { return maxMessagesPerNotification; }
			set { maxMessagesPerNotification = value; }
		}

		private string priority;

		public string Priority
		{
			get { return priority; }
			set { priority = value; }
		}

		private string separator;

		public string Separator
		{
			get { return separator; }
			set { separator = value; }
		}

		private string smtpAddresses;

		public string SmtpAddresses
		{
			get { return smtpAddresses; }
			set { smtpAddresses = value; }
		}

		private string subjectPrefix;

		public string SubjectPrefix
		{
			get { return subjectPrefix; }
			set { subjectPrefix = value; }
		}

		private string template;

		public string Template
		{
			get { return template; }
			set { template = value; }
		}

		private string to;

		public string To
		{
			get { return to; }
			set { to = value; }
		}

		public static void Add(ProviderSettingsCollection providers, HealthMonitoringProviderSettings newProvider)
		{
			if (string.IsNullOrEmpty(newProvider.Type))
			{
				throw new ArgumentException("null 또는 빈문자열은 허용되지 않습니다.", "type");
			}

			ProviderSettings provider = new ProviderSettings(newProvider.Name, newProvider.Type);
			provider.Parameters.Add("connectionStringName", newProvider.ConnectionStringName);
			provider.Parameters.Add("bcc", newProvider.Bcc);
			provider.Parameters.Add("bodyFooter", newProvider.BodyFooter);
			provider.Parameters.Add("bodyHeader", newProvider.BodyHeader);
			provider.Parameters.Add("buffer", newProvider.Buffer.ToString());
			provider.Parameters.Add("bufferMode", newProvider.BufferMode);
			provider.Parameters.Add("cc", newProvider.Cc);
			provider.Parameters.Add("commandTimeout", newProvider.CommandTimeout.ToString());
			provider.Parameters.Add("detailedTemplateErrors", newProvider.DetailedTemplateErrors.ToString());
			provider.Parameters.Add("from", newProvider.From);
			provider.Parameters.Add("maxEventDetailLength", newProvider.MaxEventDetailLength.ToString());
			provider.Parameters.Add("maxEventLengthForSimpleMessage", newProvider.MaxEventLengthForSimpleMessage.ToString());
			provider.Parameters.Add("maxSizeForSimpleMessage", newProvider.MaxSizeForSimpleMessage.ToString());
			provider.Parameters.Add("maxEventCountForTemplateMessage", newProvider.MaxEventCountForTemplateMessage.ToString());
			provider.Parameters.Add("maxMessagesPerNotification", newProvider.MaxMessagesPerNotification.ToString());
			provider.Parameters.Add("priority", newProvider.Priority);
			provider.Parameters.Add("separator", newProvider.Separator);
			provider.Parameters.Add("smtpAddresses", newProvider.SmtpAddresses);
			provider.Parameters.Add("subjectPrefix", newProvider.SubjectPrefix);
			provider.Parameters.Add("template", newProvider.Template);
			provider.Parameters.Add("to", newProvider.To);

			providers.Add(provider);
		}
		public static void Modify(ProviderSettingsCollection providers, HealthMonitoringProviderSettings provider)
		{
			if (string.IsNullOrEmpty(provider.Type))
			{
				throw new ArgumentException("null 또는 빈문자열은 허용되지 않습니다.", "type");
			}

			providers[provider.name].Type = provider.type;
			providers[provider.Name].Parameters["connectionStringName"] = provider.ConnectionStringName;
			providers[provider.Name].Parameters["bcc"] = provider.Bcc;
			providers[provider.Name].Parameters["bodyFooter"] = provider.BodyFooter;
			providers[provider.Name].Parameters["bodyHeader"] = provider.BodyHeader;
			providers[provider.Name].Parameters["buffer"] = provider.Buffer.ToString();
			providers[provider.Name].Parameters["bufferMode"] = provider.BufferMode;
			providers[provider.Name].Parameters["cc"] = provider.Cc;
			providers[provider.Name].Parameters["commandTimeout"] = provider.CommandTimeout.ToString();
			providers[provider.Name].Parameters["detailedTemplateErrors"] = provider.DetailedTemplateErrors.ToString();
			providers[provider.Name].Parameters["from"] = provider.From;
			providers[provider.Name].Parameters["maxEventDetailLength"] = provider.MaxEventDetailLength.ToString();
			providers[provider.Name].Parameters["maxEventLengthForSimpleMessage"] = provider.MaxEventLengthForSimpleMessage.ToString();
			providers[provider.Name].Parameters["maxSizeForSimpleMessage"] = provider.MaxSizeForSimpleMessage.ToString();
			providers[provider.Name].Parameters["maxEventCountForTemplateMessage"] = provider.MaxEventCountForTemplateMessage.ToString();
			providers[provider.Name].Parameters["maxMessagesPerNotification"] = provider.MaxMessagesPerNotification.ToString();
			providers[provider.Name].Parameters["priority"] = provider.Priority;
			providers[provider.Name].Parameters["separator"] = provider.Separator;
			providers[provider.Name].Parameters["smtpAddresses"] = provider.SmtpAddresses;
			providers[provider.Name].Parameters["subjectPrefix"] = provider.SubjectPrefix;
			providers[provider.Name].Parameters["template"] = provider.Template;
			providers[provider.Name].Parameters["to"] = provider.To;
		}
		public static void Remove(ProviderSettingsCollection providers, HealthMonitoringProviderSettings provider)
		{
			providers.Remove(provider.name);
		}
		public static HealthMonitoringProviderSettings ConvertToHealthMonitoringProviderSettings(ProviderSettings provider)
		{
			HealthMonitoringProviderSettings roleProvider = new HealthMonitoringProviderSettings();

			roleProvider.Name = provider.Name;
			roleProvider.Type = provider.Type;
			roleProvider.ConnectionStringName = provider.Parameters["connectionStringName"];
			roleProvider.Bcc = provider.Parameters["bcc"];
			roleProvider.BodyFooter = provider.Parameters["bodyFooter"];
			roleProvider.BodyHeader = provider.Parameters["bodyHeader"];
			roleProvider.Buffer = provider.Parameters["buffer"]!= null ? bool.Parse(provider.Parameters["buffer"]) : false;
			roleProvider.BufferMode = provider.Parameters["bufferMode"];
			roleProvider.Cc = provider.Parameters["cc"];
			roleProvider.CommandTimeout = provider.Parameters["commandTimeout"] != null ? int.Parse(provider.Parameters["commandTimeout"]) : 30;
			roleProvider.DetailedTemplateErrors = provider.Parameters["detailedTemplateErrors"] != null ? bool.Parse(provider.Parameters["detailedTemplateErrors"]) : false;
			roleProvider.From = provider.Parameters["from"];
			roleProvider.MaxEventDetailLength = provider.Parameters["maxEventDetailLength"] != null ? int.Parse(provider.Parameters["maxEventDetailLength"]) : 0;
			roleProvider.MaxEventLengthForSimpleMessage = provider.Parameters["maxEventLengthForSimpleMessage"] != null ? int.Parse(provider.Parameters["maxEventLengthForSimpleMessage"]) : 5000;
			roleProvider.MaxSizeForSimpleMessage = provider.Parameters["maxSizeForSimpleMessage"] != null ? int.Parse(provider.Parameters["maxSizeForSimpleMessage"]) : 1024;
			roleProvider.MaxEventCountForTemplateMessage = provider.Parameters["maxEventCountForTemplateMessage"] != null ? int.Parse(provider.Parameters["maxEventCountForTemplateMessage"]) : 100;
			roleProvider.MaxMessagesPerNotification = provider.Parameters["maxMessagesPerNotification"] != null ? int.Parse(provider.Parameters["maxMessagesPerNotification"]) : 100;
			roleProvider.Priority = provider.Parameters["priority"];
			roleProvider.Separator = provider.Parameters["separator"];
			roleProvider.SmtpAddresses = provider.Parameters["smtpAddresses"];
			roleProvider.SubjectPrefix = provider.Parameters["subjectPrefix"];
			roleProvider.Template = provider.Parameters["template"];
			roleProvider.To = provider.Parameters["to"];

			return roleProvider;
		}
	}

	public sealed class RequiredConnectionStringNameProviderSettings
	{
		public RequiredConnectionStringNameProviderSettings()
		{
		}

		public RequiredConnectionStringNameProviderSettings(string name, string type, string connectionStringName)
		{
			this.name = name;
			this.type = type;
			this.connectionStringName = connectionStringName;
		}

		private string name;

		public string Name
		{
			get { return name; }
			set { name = value; }
		}

		private string type;

		public string Type
		{
			get { return type; }
			set { type = value; }
		}

		private string connectionStringName;

		public string ConnectionStringName
		{
			get { return connectionStringName; }
			set { connectionStringName = value; }
		}

	
		public static void Add(ProviderSettingsCollection providers, RequiredConnectionStringNameProviderSettings newProvider)
		{
			if (string.IsNullOrEmpty(newProvider.Type))
			{
				throw new ArgumentException("null 또는 빈문자열은 허용되지 않습니다.", "type");
			}
			if (string.IsNullOrEmpty(newProvider.ConnectionStringName))
			{
				throw new ArgumentException("null 또는 빈문자열은 허용되지 않습니다.", "connectionStringName");
			}

			ProviderSettings provider = new ProviderSettings(newProvider.Name, newProvider.Type);
			provider.Parameters.Add("connectionStringName", newProvider.ConnectionStringName);

			providers.Add(provider);
		}
		public static void Modify(ProviderSettingsCollection providers, RequiredConnectionStringNameProviderSettings provider)
		{
			if (string.IsNullOrEmpty(provider.Type))
			{
				throw new ArgumentException("null 또는 빈문자열은 허용되지 않습니다.", "type");
			}
			if (string.IsNullOrEmpty(provider.ConnectionStringName))
			{
				throw new ArgumentException("null 또는 빈문자열은 허용되지 않습니다.", "connectionStringName");
			}

			providers[provider.Name].Type = provider.Type;
			providers[provider.Name].Parameters["connectionStringName"] = provider.ConnectionStringName;
		}
		public static void Remove(ProviderSettingsCollection providers, RequiredConnectionStringNameProviderSettings provider)
		{
			providers.Remove(provider.Name);
		}
		public static RequiredConnectionStringNameProviderSettings ConvertToRequiredConnectionStringNameProviderSettings(ProviderSettings provider)
		{
			RequiredConnectionStringNameProviderSettings roleProvider =
				new RequiredConnectionStringNameProviderSettings(provider.Name, provider.Type, provider.Parameters["connectionStringName"]);

			return roleProvider;
		}
	}

	public sealed class SqlMembershipProviderSettings
	{
		public SqlMembershipProviderSettings()
		{
			this.CommandTimeout = 30;
			this.EnablePasswordRetrieval = false;
			this.EnablePasswordReset = true;
			this.MaxInvalidPasswordAttempts = 5;
			this.MinRequiredNonalphanumericCharacters = 1;
			this.MinRequiredPasswordLength = 1;
			this.PasswordAttemptWindow = 10;
			this.PasswordFormat = MembershipPasswordFormat.Hashed;
			this.RequiresQuestionAndAnswer = true;
			this.RequiresUniqueEmail = true;
		}

		private String name;
		public String Name { get { return name; } set { name = value; } }

		private String type;
		public String Type { get { return type; } set { type = value; } }

		private String connectionStringName;
		public String ConnectionStringName { get { return connectionStringName; } set { connectionStringName = value; } }

		private String applicationName;
		public String ApplicationName { get { return applicationName; } set { applicationName = value; } }

		private Int32 commandTimeout;
		public Int32 CommandTimeout { get { return commandTimeout; } set { commandTimeout = value; } }

		private String description;
		public String Description { get { return description; } set { description = value; } }

		private Boolean enablePasswordRetrieval;
		public Boolean EnablePasswordRetrieval { get { return this.enablePasswordRetrieval; } set { this.enablePasswordRetrieval = value; } }

		private Boolean enablePasswordReset;
		public Boolean EnablePasswordReset { get { return this.enablePasswordReset; } set { this.enablePasswordReset = value; } }

		private Boolean requiresQuestionAndAnswer;
		public Boolean RequiresQuestionAndAnswer { get { return this.requiresQuestionAndAnswer; } set { this.requiresQuestionAndAnswer = value; } }

		private Boolean requiresUniqueEmail;
		public Boolean RequiresUniqueEmail { get { return this.requiresUniqueEmail; } set { this.requiresUniqueEmail = value; } }

		private MembershipPasswordFormat passwordFormat;
		public MembershipPasswordFormat PasswordFormat { get { return this.passwordFormat; } set { this.passwordFormat = value; } }

		private Int32 maxInvalidPasswordAttempts;
		public Int32 MaxInvalidPasswordAttempts { get { return this.maxInvalidPasswordAttempts; } set { this.maxInvalidPasswordAttempts = value; } }

		private Int32 passwordAttemptWindow;
		public Int32 PasswordAttemptWindow { get { return this.passwordAttemptWindow; } set { this.passwordAttemptWindow = value; } }

		private Int32 minRequiredPasswordLength;
		public Int32 MinRequiredPasswordLength { get { return this.minRequiredPasswordLength; } set { this.minRequiredPasswordLength = value; } }

		private Int32 minRequiredNonalphanumericCharacters;
		public Int32 MinRequiredNonalphanumericCharacters { get { return this.minRequiredNonalphanumericCharacters; } set { this.minRequiredNonalphanumericCharacters = value; } }

		private String passwordStrengthRegularExpression;
		public String PasswordStrengthRegularExpression { get { return this.passwordStrengthRegularExpression; } set { this.passwordStrengthRegularExpression = value; } }

		public static void Add(ProviderSettingsCollection providers, SqlMembershipProviderSettings newProvider)
		{
			if (string.IsNullOrEmpty(newProvider.Type))
			{
				throw new ArgumentException("null 또는 빈문자열은 허용되지 않습니다.", "type");
			}
			if (string.IsNullOrEmpty(newProvider.ConnectionStringName))
			{
				throw new ArgumentException("null 또는 빈문자열은 허용되지 않습니다.", "connectionStringName");
			}

			ProviderSettings provider = new ProviderSettings(newProvider.Name, newProvider.Type);
			provider.Parameters.Add("connectionStringName", newProvider.ConnectionStringName);
			provider.Parameters.Add("applicationName", newProvider.ApplicationName);
			provider.Parameters.Add("commandTimeout", newProvider.CommandTimeout.ToString() ?? "30");
			provider.Parameters.Add("description", newProvider.Description);
			provider.Parameters.Add("enablePasswordRetrieval", newProvider.EnablePasswordRetrieval.ToString() ?? "false");
			provider.Parameters.Add("enablePasswordReset", newProvider.EnablePasswordReset.ToString() ?? "true");
			provider.Parameters.Add("requiresQuestionAndAnswer", newProvider.RequiresQuestionAndAnswer.ToString() ?? "true");
			provider.Parameters.Add("requiresUniqueEmail", newProvider.RequiresUniqueEmail.ToString() ?? "true");
			provider.Parameters.Add("passwordFormat", newProvider.PasswordFormat.ToString());
			provider.Parameters.Add("maxInvalidPasswordAttempts", newProvider.MaxInvalidPasswordAttempts.ToString() ?? "5");
			provider.Parameters.Add("passwordAttemptWindow", newProvider.PasswordAttemptWindow.ToString() ?? "10");
			provider.Parameters.Add("minRequiredPasswordLength", newProvider.MinRequiredPasswordLength.ToString() ?? "1");
			provider.Parameters.Add("minRequiredNonalphanumericCharacters", newProvider.MinRequiredNonalphanumericCharacters.ToString() ?? "1");
			provider.Parameters.Add("passwordStrengthRegularExpression", newProvider.PasswordStrengthRegularExpression);

			providers.Add(provider);
		}
		public static void Modify(ProviderSettingsCollection providers, SqlMembershipProviderSettings provider)
		{
			if (string.IsNullOrEmpty(provider.Type))
			{
				throw new ArgumentException("null 또는 빈문자열은 허용되지 않습니다.", "type");
			}
			if (string.IsNullOrEmpty(provider.ConnectionStringName))
			{
				throw new ArgumentException("null 또는 빈문자열은 허용되지 않습니다.", "connectionStringName");
			}

			providers[provider.Name].Type = provider.Type;
			providers[provider.Name].Parameters["connectionStringName"] = provider.ConnectionStringName;
			providers[provider.Name].Parameters["applicationName"] = provider.ApplicationName;
			providers[provider.Name].Parameters["commandTimeout"] = provider.CommandTimeout.ToString() ?? "30";
			providers[provider.Name].Parameters["description"] = provider.Description;
			providers[provider.Name].Parameters["enablePasswordRetrieval"] = provider.EnablePasswordRetrieval.ToString() ?? "false";
			providers[provider.Name].Parameters["enablePasswordReset"] = provider.EnablePasswordReset.ToString() ?? "true";
			providers[provider.Name].Parameters["requiresQuestionAndAnswer"] = provider.RequiresQuestionAndAnswer.ToString() ?? "true";
			providers[provider.Name].Parameters["requiresUniqueEmail"] = provider.RequiresUniqueEmail.ToString() ?? "true";
			providers[provider.Name].Parameters["passwordFormat"] = provider.PasswordFormat.ToString();
			providers[provider.Name].Parameters["maxInvalidPasswordAttempts"] = provider.MaxInvalidPasswordAttempts.ToString() ?? "5";
			providers[provider.Name].Parameters["passwordAttemptWindow"] = provider.PasswordAttemptWindow.ToString() ?? "10";
			providers[provider.Name].Parameters["minRequiredPasswordLength"] = provider.MinRequiredPasswordLength.ToString() ?? "1";
			providers[provider.Name].Parameters["minRequiredNonalphanumericCharacters"] = provider.MinRequiredNonalphanumericCharacters.ToString() ?? "1";
			providers[provider.Name].Parameters["passwordStrengthRegularExpression"] = provider.PasswordStrengthRegularExpression;
		}
		public static void Remove(ProviderSettingsCollection providers, SqlMembershipProviderSettings provider)
		{
			providers.Remove(provider.Name);
		}
		public static SqlMembershipProviderSettings ConvertToSqlMembershipProviderSettings(ProviderSettings provider)
		{
			SqlMembershipProviderSettings toProvider = new SqlMembershipProviderSettings();
			toProvider.Name = provider.Name;
			toProvider.Type = provider.Type;
			toProvider.ConnectionStringName = provider.Parameters["connectionStringName"];
			toProvider.ApplicationName = provider.Parameters["applicationName"];
			toProvider.CommandTimeout = String.IsNullOrEmpty(provider.Parameters["commandTimeout"]) ? 30 : Int32.Parse(provider.Parameters["commandTimeout"]);
			toProvider.Description = provider.Parameters["description"];
			toProvider.EnablePasswordRetrieval = String.IsNullOrEmpty(provider.Parameters["enablePasswordRetrieval"]) ? false : Boolean.Parse(provider.Parameters["enablePasswordRetrieval"]);
			toProvider.EnablePasswordReset = String.IsNullOrEmpty(provider.Parameters["enablePasswordReset"]) ? true : Boolean.Parse(provider.Parameters["enablePasswordReset"]);
			toProvider.RequiresQuestionAndAnswer = String.IsNullOrEmpty(provider.Parameters["requiresQuestionAndAnswer"]) ? true : Boolean.Parse(provider.Parameters["requiresQuestionAndAnswer"]);
			toProvider.RequiresUniqueEmail = String.IsNullOrEmpty(provider.Parameters["requiresUniqueEmail"]) ? true : Boolean.Parse(provider.Parameters["requiresUniqueEmail"]);
			toProvider.PasswordFormat = String.IsNullOrEmpty(provider.Parameters["passwordFormat"]) ? MembershipPasswordFormat.Hashed : (MembershipPasswordFormat)Enum.Parse(typeof(MembershipPasswordFormat), provider.Parameters["passwordFormat"]);
			toProvider.MaxInvalidPasswordAttempts = String.IsNullOrEmpty(provider.Parameters["maxInvalidPasswordAttempts"]) ? 5 : Int32.Parse(provider.Parameters["maxInvalidPasswordAttempts"]);
			toProvider.PasswordAttemptWindow = String.IsNullOrEmpty(provider.Parameters["passwordAttemptWindow"]) ? 10 : Int32.Parse(provider.Parameters["passwordAttemptWindow"]);
			toProvider.MinRequiredPasswordLength = String.IsNullOrEmpty(provider.Parameters["minRequiredPasswordLength"]) ? 1 : Int32.Parse(provider.Parameters["minRequiredPasswordLength"]);
			toProvider.MinRequiredNonalphanumericCharacters = String.IsNullOrEmpty(provider.Parameters["minRequiredNonalphanumericCharacters"]) ? 1 : Int32.Parse(provider.Parameters["minRequiredNonalphanumericCharacters"]);
			toProvider.PasswordStrengthRegularExpression = provider.Parameters["passwordStrengthRegularExpression"];

			return toProvider;
		}
	}

	public sealed class SqlProfileProviderSettings
	{
		public SqlProfileProviderSettings()
		{
			this.CommandTimeout = 30;
		}

		private String name;
		public String Name { get { return this.name; } set { this.name = value; } }

		private String type;
		public String Type { get { return this.type; } set { this.type = value; } }

		private String connectionStringName;
		public String ConnectionStringName { get { return this.connectionStringName; } set { this.connectionStringName = value; } }

		private Int32 commandTimeout;
		public Int32 CommandTimeout { get { return this.commandTimeout; } set { this.commandTimeout = value; } }

		private String description;
		public String Description { get { return this.description; } set { this.description = value; } }

		private String applicationName;
		public String ApplicationName { get { return this.applicationName; } set { this.applicationName = value; } }

		public static void Add(ProviderSettingsCollection providers, SqlProfileProviderSettings newProvider)
		{
			if (string.IsNullOrEmpty(newProvider.Type))
			{
				throw new ArgumentException("null 또는 빈문자열은 허용되지 않습니다.", "type");
			}
			if (string.IsNullOrEmpty(newProvider.ConnectionStringName))
			{
				throw new ArgumentException("null 또는 빈문자열은 허용되지 않습니다.", "connectionStringName");
			}

			ProviderSettings provider = new ProviderSettings(newProvider.Name, newProvider.Type);
			provider.Parameters.Add("connectionStringName", newProvider.ConnectionStringName);
			provider.Parameters.Add("commandTimeout", newProvider.CommandTimeout.ToString() ?? "30");
			provider.Parameters.Add("description", newProvider.Description);
			provider.Parameters.Add("applicationName", newProvider.ApplicationName);

			providers.Add(provider);
		}
		public static void Modify(ProviderSettingsCollection providers, SqlProfileProviderSettings provider)
		{
			if (string.IsNullOrEmpty(provider.Type))
			{
				throw new ArgumentException("null 또는 빈문자열은 허용되지 않습니다.", "type");
			}
			if (string.IsNullOrEmpty(provider.ConnectionStringName))
			{
				throw new ArgumentException("null 또는 빈문자열은 허용되지 않습니다.", "connectionStringName");
			}

			providers[provider.Name].Type = provider.Type;
			providers[provider.Name].Parameters["connectionStringName"] = provider.ConnectionStringName;
			providers[provider.Name].Parameters["commandTimeout"] = provider.CommandTimeout.ToString() ?? "30";
			providers[provider.Name].Parameters["description"] = provider.Description;
			providers[provider.Name].Parameters["applicationName"] = provider.ApplicationName;
		}
		public static void Remove(ProviderSettingsCollection providers, SqlProfileProviderSettings provider)
		{
			providers.Remove(provider.Name);
		}
		public static SqlProfileProviderSettings ConvertToSqlProfileProviderSettings(ProviderSettings provider)
		{
			SqlProfileProviderSettings toProvider = new SqlProfileProviderSettings();
			toProvider.Name = provider.Name;
			toProvider.Type = provider.Type;
			toProvider.ConnectionStringName = provider.Parameters["connectionStringName"];
			toProvider.CommandTimeout = String.IsNullOrEmpty(provider.Parameters["commandTimeout"]) ? 30 : Int32.Parse(provider.Parameters["commandTimeout"]);
			toProvider.Description = provider.Parameters["description"];
			toProvider.ApplicationName = provider.Parameters["applicationName"];
			return toProvider;
		}
	}

	public sealed class SqlRoleProviderSettings
	{
		public SqlRoleProviderSettings()
		{
			this.CommandTimeout = 30;
		}

		private String name;
		public String Name { get { return this.name; } set { this.name = value; } }

		private String type;
		public String Type { get { return this.type; } set { this.type = value; } }

		private String connectionStringName;
		public String ConnectionStringName { get { return this.connectionStringName; } set { this.connectionStringName = value; } }

		private Int32 commandTimeout;
		public Int32 CommandTimeout { get { return this.commandTimeout; } set { this.commandTimeout = value; } }

		private String description;
		public String Description { get { return this.description; } set { this.description = value; } }

		private String applicationName;
		public String ApplicationName { get { return this.applicationName; } set { this.applicationName = value; } }

		public static void Add(ProviderSettingsCollection providers, SqlRoleProviderSettings newProvider)
		{
			if (string.IsNullOrEmpty(newProvider.Type))
			{
				throw new ArgumentException("null 또는 빈문자열은 허용되지 않습니다.", "type");
			}
			if (string.IsNullOrEmpty(newProvider.ConnectionStringName))
			{
				throw new ArgumentException("null 또는 빈문자열은 허용되지 않습니다.", "connectionStringName");
			}

			ProviderSettings provider = new ProviderSettings(newProvider.Name, newProvider.Type);
			provider.Parameters.Add("connectionStringName", newProvider.ConnectionStringName);
			provider.Parameters.Add("commandTimeout", newProvider.CommandTimeout.ToString() ?? "30");
			provider.Parameters.Add("description", newProvider.Description);
			provider.Parameters.Add("applicationName", newProvider.ApplicationName);

			providers.Add(provider);
		}
		public static void Modify(ProviderSettingsCollection providers, SqlRoleProviderSettings provider)
		{
			if (string.IsNullOrEmpty(provider.Type))
			{
				throw new ArgumentException("null 또는 빈문자열은 허용되지 않습니다.", "type");
			}
			if (string.IsNullOrEmpty(provider.ConnectionStringName))
			{
				throw new ArgumentException("null 또는 빈문자열은 허용되지 않습니다.", "connectionStringName");
			}

			providers[provider.Name].Type = provider.Type;
			providers[provider.Name].Parameters["connectionStringName"] = provider.ConnectionStringName;
			providers[provider.Name].Parameters["commandTimeout"] = provider.CommandTimeout.ToString() ?? "30";
			providers[provider.Name].Parameters["description"] = provider.Description;
			providers[provider.Name].Parameters["applicationName"] = provider.ApplicationName;
		}
		public static void Remove(ProviderSettingsCollection providers, SqlRoleProviderSettings provider)
		{
			providers.Remove(provider.Name);
		}
		public static SqlRoleProviderSettings ConvertToSqlRoleProviderSettings(ProviderSettings provider)
		{
			SqlRoleProviderSettings toProvider = new SqlRoleProviderSettings();
			toProvider.Name = provider.Name;
			toProvider.Type = provider.Type;
			toProvider.ConnectionStringName = provider.Parameters["connectionStringName"];
			toProvider.CommandTimeout = String.IsNullOrEmpty(provider.Parameters["commandTimeout"]) ? 30 : Int32.Parse(provider.Parameters["commandTimeout"]);
			toProvider.Description = provider.Parameters["description"];
			toProvider.ApplicationName = provider.Parameters["applicationName"];
			return toProvider;
		}
	}
}